home *** CD-ROM | disk | FTP | other *** search
/ Aminet 5 / Aminet 5 - March 1995.iso / Aminet / comm / mail / SendMail_rxJD.lzh / SendMail.rx
Text File  |  1995-01-09  |  10KB  |  195 lines

  1. /* filename: SendMail.rx                                                    */
  2. /*  version: 1.3     15 Dec 94     (c)1994 James E. Dutton                  */
  3. /*  purpose: take input file in Internet RFC822 (e-mail) format and convert */
  4. /*           it into .txt and .wrk files for delivery via an SMTP client    */
  5. /*   syntax: (rx) SendMail <[input file specs]                              */
  6. /*    notes: while this program can be invoked manually, it is intended to  */
  7. /*           be called by AmigaELM as a replacement for other SendMail      */
  8. /*           programs                                                       */
  9. /*   author: Jim Dutton                                                     */
  10. /*           jimd@slip106.termserv.siu.edu                                  */
  11. /*           ca0008@siucvmb.siu.edu                                         */
  12. /* comments: Inspired by Sendmail.rx version 19931205 by Dan Rowan          */
  13. /*                                                                          */
  14. /*           To invoke from AmigaELM, add/modify the "Sendmail"/"Rmail"     */
  15. /*           configuration parameters similar to (using your own directory) */
  16. /*                                                                          */
  17. /*                    SendMail rexxc:rx tcpip:sendmail.rx <$MSG             */
  18. /*                    RMail rexxc:rx tcpip:sendmail.rx <$MSG $TO            */
  19. /*                                                                          */
  20. /*           Some SMTP clients (eg; AmigaNOS) are not able to deal with MX  */
  21. /*           records (or target hosts which do not sport an SMTP server and */
  22. /*           require a seperate mail host to receive mail); an ARexx clip   */
  23. /*           list, needMXlist, is used to find which known hosts use an MX  */
  24. /*           record; another ARexx clip list is used to provide a known mail*/
  25. /*           host which corresponds to the MX record for the original target*/
  26. /*           host, and is called "useMXlist"; both of these lists are built */
  27. /*           and maintained manually by the user via the ARexx RXSET command*/
  28. /*                                                                          */
  29. /*           For example:                                                   */
  30. /*           RXSET needMXlist gwalter.demon.co.uk ppp11.llc.org aston.ac.uk */
  31. /*           RXSET useMXlist post.demon.co.uk biko.llc.org email.aston.ac.uk*/
  32. /*                                                                          */
  33. /*           There is a simple one-to-one correspondance between a known    */
  34. /*           host in the needMXlist and the useMXlist. You will need access */
  35. /*           to something like the NSLOOKUP program to find out the MX      */
  36. /*           record(s) associated with a given host, or you will need to    */
  37. /*           find a Domain Name Server related person who can find out that */
  38. /*           information for you.                                           */
  39. /*                                                                          */
  40. /*           You will need to change the value of the DefaultMailer variable*/
  41. /*           to the host name of a "smart(er)" mail (SMTP) server which can */
  42. /*           resolve host names that your SMTP client cannot; this should be*/
  43. /*           an SMTP server (gateway) within your existing domain/network   */
  44. /*                                                                          */
  45. /*           This SendMail program will process carbon copies and blind     */
  46. /*           carbon copies, but the keywords MUST be spelled correctly (see */
  47. /*           Select clause below), and begin on seperate lines              */
  48. /*                                                                          */
  49. /*           This program also allows MULTIPLE To:, Cc:, or Bcc: targets IF */
  50. /*           each target is immediately followed by a comma (except for the */
  51. /*           LAST target, of course) (eg; <target1>, <target2>)             */
  52. /*                                                                          */
  53. /*           To:, Cc:, and Bcc: target lists may cover more than one line IF*/
  54. /*           each line (but the last one) is terminated with a comma        */
  55. /*                                                                          */
  56. /*           A log file is maintained for every note that is processed. A   */
  57. /*           few real sample log entries are:                               */
  58. /*                                                                          */
  59. /* 20 Nov 1994 12:49:24 To: "Allen Wittenauer" <allenw@som.siu.edu> Subject: Re: Uproar? */
  60. /* 22 Nov 1994 19:54:23 To: majordomo@NetBSD.ORG Subject: lists             */
  61. /*                                                                          */
  62. /*           You should modify the path for this log file to conform to your*/
  63. /*           system (set in variable MailLogFile below)                     */
  64. /*                                                                          */
  65. /*           The path for the SMTP client's mail queue on your system should*/
  66. /*           be verified against the MQueue variable below                  */
  67. /*                                                                          */
  68. /*           A working (temporary) copy of the note to be sent is kept on   */
  69. /*           the T: device                                                  */
  70. /*                                                                          */
  71. /*           This (pseudo) SendMail program is by NO means, exhaustive      */
  72.  
  73. Call Initialize
  74. Call ProcessInput
  75. Call CreateMqueue
  76. Call CloseUp
  77. Exit
  78.  
  79.  
  80. CloseUp:
  81.   duh = open(seqfile,MQueue'/sequence.seq','W')
  82.   duh = writech(seqfile,seq);  duh = close(seqfile)
  83.   duh = close(STDERR); duh = close(STDOUT); duh = close(maillog)
  84.   Address 'COMMAND' 'Delete T:tempfile.txt'
  85. Return
  86.  
  87.  
  88. Initialize:
  89.   DefaultMailer = "?"; MailLogFile = "TCPIP:Logs/Mail.log"
  90.   MQueue = "TCPIP:spool/mqueue"
  91.   EndOfHeaders = no;  ReturnTrip = no;  TargetNum = 0;  tabchar = '09'x
  92.  
  93.   If ~open(seqfile,MQueue'/sequence.seq','R') then
  94.     Do; say "***Can't open sequence.seq file, aborting!"; Exit 20; End
  95.   seq = readln(seqfile); duh = close(seqfile)
  96.  
  97.   needMXlist = getclip("needMXlist")    /* list of known hosts which require an MX host */
  98.   useMXlist = getclip("useMXlist")      /* use these MX hosts instead of host above */
  99.   If needMXlist = "" then needMXlist = "?"         /* dummy record */
  100.   Else  upper needMXlist
  101.   If useMXlist = ""  then useMXlist = "?"          /* dummy record */
  102.   Else  upper useMXlist
  103.  
  104.   If open(timezone,'ENV:TZ','R') then;  Do; tz=left(readln(timezone),3); duh = close(timezone); End
  105.   Else  tz = "GMT"
  106.  
  107.   If ~open(maillog,MailLogFile,"A")  then  duh = open(maillog,MailLogFile,"W")
  108.   duh = open(STDERR,"T:SendmailErrors","W"); duh = open(STDOUT,"T:SendmailConsole","W")
  109.   duh = open(tempfile,"T:tempfile.txt","W")
  110.   duh = writeln(tempfile,'Date: '|| left(date('W'),3) ||', '|| date() ||' '|| time()||' '||tz)
  111. Return
  112.  
  113.  
  114. ProcessInput:
  115.   Do while EndOfHeaders = no
  116.     inline = strip(readln(STDIN))
  117.     If substr(inline,1,5) ~= "Bcc: "  then   duh = writeln(tempfile,inline)
  118.     Select
  119.         When  substr(inline,1,6) = "From: "     then  Call  ProcessFromLine
  120.         When  substr(inline,1,4) = "To: "       then  Call  ProcessToLines
  121.         When  substr(inline,1,4) = "Cc: "       then  Call  ProcessToLines
  122.         When  substr(inline,1,9) = "Subject: "  then  subjline = inline
  123.         When  substr(inline,1,5) = "Bcc: "      then  Call  ProcessToLines
  124.         When  ReturnTrip        ~= no           Then  Interpret "Call" ReturnTrip
  125.         Otherwise;              If inline = ""  then  EndOfHeaders = yes
  126.     End
  127.   End
  128.  
  129.   Do while ~eof(STDIN);  duh = writeln(tempfile,readln(STDIN));  End
  130.   duh = close(STDIN);  duh = close(tempfile)
  131. Return
  132.  
  133.  
  134. ProcessFromLine:
  135.   If pos("<",inline) > 0  then   parse var inline "<"sendinguser">"
  136.   Else parse var inline . sendinguser .
  137. Return
  138.  
  139.  
  140. ProcessToLines:
  141.   If pos(",",inline) > 0  then
  142.     Do;  ReturnTrip = "ProcessToLines"; parse var inline inline","; End
  143.   Else  ReturnTrip = no
  144.  
  145.   TargetNum = TargetNum + 1;  ToLine.TargetNum = inline
  146.   If pos("<",inline) > 0  then   parse var inline "<"targetuser">"
  147.   Else
  148.   If pos("(",inline) > 0  then
  149.     Do
  150.       parse var inline before"(".")"after;  before = strip(before)
  151.       If before ~= ""  then  targetuser = before
  152.       Else targetuser = after
  153.  
  154.       If pos(":",targetuser) > 0  then  targetuser = subword(targetuser,2)
  155.       Else
  156.       If substr(targetuser,1,1) = tabchar  then  parse var targetuser . +1 targetuser
  157.     End
  158.   Else  targetuser = subword(inline,2)
  159.  
  160.   /* determine initial host to route mail to */
  161.   If pos("%",targetuser) > 0  then
  162.     Do
  163.       parse var targetuser userid"%"userhost"@"routinghost .
  164.       targetuser = userid"@"userhost
  165.     End
  166.   Else  parse var targetuser"@"routinghost .
  167.  
  168.   /* check for known hosts who require an (alternative) MX host */
  169.   uppered_routinghost = routinghost;  upper uppered_routinghost
  170.   loc = find(needMXlist,uppered_routinghost)
  171.   If loc > 0  then  routinghost = word(useMXlist,loc)
  172.  
  173.   /* check for nasty UUCP addresses and convert */
  174.   upper inline
  175.   If pos("UUCP",inline) > 0  then
  176.     Do
  177.        routinghost = DefaultMailer; parse var targethost lhs"@"rhs".uucp" .
  178.        targetuser = lhs"%"rhs"@uunet.uu.net"
  179.     End
  180.  
  181.   TargetUser.TargetNum = targetuser;  RoutingHost.TargetNum = routinghost
  182. Return
  183.  
  184.  
  185. CreateMqueue:
  186.   Do i = 1 to TargetNum
  187.     seq = seq + 1
  188.     duh = writeln(maillog,date() time() ToLine.i subjline)
  189.     duh = open(mailwrk,MQueue'/'seq'.wrk','W')
  190.     duh = writeln(mailwrk,RoutingHost.i); duh = writeln(mailwrk,sendinguser)
  191.     duh = writeln(mailwrk,TargetUser.i);  duh = close(mailwrk)
  192.     Address 'COMMAND' 'COPY T:tempfile.txt TO' MQueue'/'seq'.txt'
  193.   End
  194. Return
  195.